package com.demo;

/**
 * @ClassName: SingletonPattern
 * @Description: 饿汉式
 * @Date: 2020/11/19 09:47
 */
public class Singleton {
    //刚开始就创建一个对象，不管你用不用
    private static Singleton singleton;
    static {
        singleton=new Singleton();
    }
    private Singleton(){}//私有构造方法
    public static Singleton getInstance(){
        return singleton;
    }
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1==s2);
    }
}